package com.scheduler.backend.aps.domain.deadlinefirst;

import com.scheduler.backend.aps.domain.Equipment;
import com.scheduler.backend.aps.domain.Resource;
import com.scheduler.backend.aps.domain.ResourceGroup;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty;
import org.optaplanner.core.api.domain.solution.PlanningScore;
import org.optaplanner.core.api.domain.solution.PlanningSolution;
import org.optaplanner.core.api.domain.valuerange.CountableValueRange;
import org.optaplanner.core.api.domain.valuerange.ValueRangeFactory;
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider;
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;

import java.util.Collections;
import java.util.List;

/**
 * @author heimingz
 */

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@PlanningSolution
public class ScheduleTable {
    /**
     * 订单切片的时间片跨度
     */
    public static final int ORDER_SLICE_TIMESLOT_SPAN = 1;

    /**
     * 订单切片的单个时间片用时(分钟)
     */
    public static final long ORDER_SLICE_MINUTES = 4 * 60;

    /**
     * NULL工作小组
     */
    public static final ResourceGroup NULL_TEAM = new ResourceGroup("null", "null", 0L, Collections.emptyList());
    /**
     * NULL设备
     */
    public static final Resource NULL_EQUIPMENT = new Equipment("null", "null", null);

    private Long timeslotRange;

    @PlanningEntityCollectionProperty
    private List<OrderSlice> orderSlices;

    @PlanningScore
    private HardSoftScore score;

    public ScheduleTable(Long timeslotRange, List<OrderSlice> orderSlices) {
        this.timeslotRange = timeslotRange;
        this.orderSlices = orderSlices;
    }

    @ValueRangeProvider(id = "timeslotRange")
    public CountableValueRange<Long> getTimeslotRange() {
        return ValueRangeFactory.createLongValueRange(0, timeslotRange);
    }
}